{% extends "layout.html" %}
{% load currency_filters %}
{% load i18n %}

{% block title %}
{% trans 'My account' %} | {{ block.super }}
{% endblock %}

{% block body_class %}account-profile{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
        <a href="{% url promotions:home %}">{% trans 'Home' %}</a>
        <span class="divider">/</span>
    </li>
    <li class="active">{% trans 'Account' %}</li>
</ul>
{% endblock %}

{% block headertext %}
{% trans 'Account' %}
{% endblock %}

{% block content %}

<div class="tabbable">

    <div class="navbar nav-profile">
        <div class="navbar-inner">
            <div class="container">

                <a class="btn btn-navbar" data-toggle="collapse" data-target=".profile-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>

                <span class="brand visible-phone" href="#">Account</span>

                <div class="nav-collapse profile-collapse">
                    <ul class="nav nav-tabs">
                        <li {% if active_tab == 'profile' %}class="active"{% endif %}><a href="#profile" data-toggle="tab">{% trans 'Profile' %}</a></li>
                        <li {% if active_tab == 'orders' %}class="active"{% endif %}><a href="#orders" data-toggle="tab">{% trans 'Order History' %}</a></li>
                        <li {% if active_tab == 'addresses' %}class="active"{% endif %}><a href="#addresses" data-toggle="tab">{% trans 'Address Book' %}</a></li>
                        <li {% if active_tab == 'emails' %}class="active"{% endif %}><a href="#emails" data-toggle="tab">{% trans 'Email History' %}</a></li>
                        <li {% if active_tab == 'alerts' %}class="active"{% endif %}><a href="#alerts" data-toggle="tab">{% trans "Alerts" %}</a></li>
                        {% block extra_tabs_nav %}
                        {% endblock %}
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="tab-content">

        <div class="tab-pane {% if active_tab == 'profile' %}active{% endif %}" id="profile">
            {% block tab_profile %}
            <div class="sub-header">
                <h3>{% trans 'Profile' %}</h3>
            </div>
            <table class="table table-striped table-bordered">
                <tbody>
                    <tr>
                        <th>{% trans 'Name' %}</th>
                        <td>{{ request.user.get_full_name|default:'-' }}</td>
                    </tr>
                    <tr>
                        <th>{% trans 'Email address' %}</th>
                        <td>{{ user.email }}</td>
                    </tr>
                    {% block profile_fields %}
                    {% for field in profile_fields %}
                    <tr>
                        <th>{{ field.name }}</th>
                        <td>{{ field.value|default:"-" }}</td>
                    </tr>
                    {% endfor %}
                    {% endblock %}
                    <tr>
                        <th>{% trans 'Date registered' %}</th>
                        <td>{{ user.date_joined }}</td>
                    </tr>
                </tbody>
            </table>

            <div class="form-actions">
                <!--<a href="{% url customer:profile-update %}" class="btn btn-primary">{% trans 'Edit profile' %}</a>-->
                <a href="{% url customer:change-password %}" class="btn btn-danger">{% trans 'Change password' %}</a>
            </div>
            {% endblock %}
        </div>

        <div class="tab-pane {% if active_tab == 'orders' %}active{% endif %}" id="orders">
            {% block tab_orderhistory %}
            <div class="sub-header">
                <h3>{% trans 'Order history' %}</h3>
            </div>

            {% if orders %}
            <table class="table table-striped table-bordered">
                <tr>
                    <th>{% trans 'Order number' %}</th>
                    <th>{% trans 'Total inc tax' %}</th>
                    <th>{% trans 'Date submitted' %}</th>
                    <th></th>
                </tr>
                {% for order in orders %}
                <tr>
                    <td>{{ order.number }}</td>
                    <td>{{ order.total_incl_tax|currency }}</td>
                    <td>{{ order.date_placed }}</td>
                    <td>
                        <a class="btn btn-info" href="{% url customer:order order.number %}">{% trans 'View' %}</a>
                        <form action="{% url customer:order order.number %}" method="post">
                            {% csrf_token %}
                            <input type="hidden" name="order_id" value="{{ order.id }}" />
                            <input type="hidden" name="action" value="reorder" />
                            <!--<button type="submit" class="btn btn-success">{% trans 'Re-order' %}</button>-->
                        </form>
                    </td>
                </tr>
                {% endfor %}
            </table>

            <div class="form-actions">
                <a href="{% url customer:order-list %}" class="btn btn-primary">{% trans 'View order history' %}</a>
            </div>
            {% else %}
            <p>{% trans "You haven't placed any orders yet." %}</p>
            {% endif %}
            {% endblock %}
        </div>

        <div class="tab-pane {% if active_tab == 'addresses' %}active{% endif %}" id="addresses">
            {% block tab_addressbook %}
            <div class="sub-header">
                <h3>{% trans "Address book" %}</h3>
            </div>
            <table class="table table-striped table-bordered">
                <tbody>
                    <tr>
                        <th>{% trans 'Number of addresses in addressbook' %}</th>
                        <td>{{ addressbook_size }}</td>
                    </tr>
                    <tr>
                        <th>{% trans 'Default shipping address' %}</th>
                        <td>{{ default_shipping_address|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th>{% trans 'Default billing address' %}</th>
                        <td>{{ default_billing_address|default:"-" }}</td>
                    </tr>
                </tbody>
            </table>

            <div class="form-actions">
                <a href="{% url customer:address-list %}" class="btn btn-primary">{% trans 'Manage address book' %}</a>
            </div>

            {% endblock %}
        </div>

        <div class="tab-pane {% if active_tab == 'emails' %}active{% endif %}" id="emails">
            {% block tab_emailhistory %}
            <div class="sub-header">
                <h3>{% trans 'Email history' %}</h3>
            </div>
            {% if not emails %}

            <p>{% trans "You haven't been sent any emails yet." %}</p>

            {% else %}

            <table class="table table-striped table-bordered">
                <tr>
                    <th>{% trans 'Date sent' %}</th>
                    <th>{% trans 'Subject' %}</th>
                    <th></th>
                </tr>
                {% for email in emails %}
                <tr>
                    <td>{{ email.date_sent }}</td>
                    <td>{{ email.subject }}</td>
                    <td>
                        <a href="{% url customer:email-detail email.id %}" class="btn btn-info">{% trans 'View' %}</a>
                    </td>
                </tr>
                {% endfor %}
            </table>

            <div class="form-actions">
                <a href="{% url customer:email-list %}" class="btn btn-primary">{% trans 'View email history' %}</a>
            </div>

            {% endif %}
            {% endblock %}
        </div>

        <div class="tab-pane {% if active_tab == 'alerts' %}active{% endif %}" id="alerts">
            {% block tab_alerts %}
            <div class="sub-header">
                <h3>{% trans "Alerts" %}</h3>
            </div>

            {% if not alerts %}
            <p>{% trans "You do not have any active alerts for out-of-stock products." %}</p>
            {% else %}
                <form action="." method="post" id="alerts_form">
                {% csrf_token %}
                    <table class="table table-stiped table-bordered">
                        <tr>
                            <th>{% trans "Product" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th>{% trans "Date created" %}</th>
                            <th></th>
                        </tr>

                        {% for alert in alerts %}
                        <tr>
                            <td>
                                {% with product=alert.product %}
                                <a href="{{ product.get_absolute_url }}">{{ product.get_title }}</a>
                                {% endwith %}
                            </td>
                            <td>{{ alert.status }}</td>
                            <td>{{ alert.date_created }}</td>
                            <td>
                                {% if alert.can_be_cancelled %}
                                    <button class="btn btn-danger" type='submit' name='cancel_alert' value='{{ alert.id }}'>{% trans "Cancel" %}</button>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </table>
                </form>
            {% endif %}

            {% endblock %}
        </div>

        {% block extra_tabs %}
        {% endblock %}

    </div>
</div><!--End of tab-content -->

{% endblock content %}

{% block onbodyload %}
oscar.account.init();
{% endblock %}
